﻿using DevExpress.Xpo.DB;
using System.Data;

namespace Kuiper.Core.Providers;

public class KpMsSQLConnectionProvider : MSSqlConnectionProvider, IDisposable
{
	private bool _disposed;

	public KpMsSQLConnectionProvider(IDbConnection connection, AutoCreateOption autoCreateOption) : base(connection, autoCreateOption)
	{
	}

	public new static string GetConnectionString(string server, string database)
	{
		return $"{XpoProviderTypeParameterName}={XpoProviderTypeString};data source={server};Integrated Security=SSPI;initial catalog={database};packet size=4096;ConnectRetryCount=0;TrustServerCertificate=true";
	}

	public void Dispose()
	{
		if (_disposed) return;

		_disposed = true;
		Connection?.Dispose();
	}
}
